package com.example.hemin.fnb.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hemin.fnb.R;
import com.example.hemin.fnb.ui.adapter.ShopOrderAdapter;
import com.example.hemin.fnb.ui.base.BaseMvpActivity;
import com.example.hemin.fnb.ui.bean.ShopOrderBean;
import com.example.hemin.fnb.ui.util.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShopOrders extends BaseMvpActivity {
    @BindView(R.id.lay_back)
    LinearLayout layBack;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.text2)
    TextView text2;
    @BindView(R.id.text3)
    TextView text3;
    @BindView(R.id.text4)
    TextView text4;
    @BindView(R.id.image2)
    ImageView image2;
    @BindView(R.id.c1)
    ConstraintLayout c1;
    @BindView(R.id.address_recyclerview)
    RecyclerView addressRecyclerview;
    @BindView(R.id.b_titl1)
    TextView bTitl1;
    @BindView(R.id.b_titl2)
    TextView bTitl2;
    @BindView(R.id.b_titl3)
    TextView bTitl3;
    private List<ShopOrderBean> beans = new ArrayList<>();
    private boolean isBooleans  = false;

    @Override
    public int getLayoutId() {
        return R.layout.shopp_orders;
    }

    @Override
    public void initView() {
        title.setText("确定订单");
        SharedPreferences sp = getSharedPreferences("userAddress", Context.MODE_PRIVATE);
        String name = sp.getString("name","");
        String phone = sp.getString("phone","");
        String address = sp.getString("address","");

        if(name != null && phone != null && address != null ){
            bTitl3.setBackgroundResource(R.drawable.textview_border_red);
            bTitl3.setClickable(true);
               isBooleans = true;
        }else{
            bTitl3.setBackgroundResource(R.drawable.textview_border_hui);
          bTitl3.setClickable(false);
          isBooleans = false;
        }
        if(name != null && phone != null&& address != null){
            text4.setVisibility(View.GONE);
            text.setVisibility(View.VISIBLE);
            text2.setVisibility(View.VISIBLE);
            text3.setVisibility(View.VISIBLE);
            text.setText(name);
            text2.setText(phone);
            text3.setText(address);
        }
        initDate();


    }

    private void initDate() {
        for (int i = 0; i < 10; i++) {
            ShopOrderBean bean = new ShopOrderBean("dwda", "作曲家", "￥3000", "5", "到付");
            ShopOrderBean bean2 = new ShopOrderBean("dwda", "画家", "￥8000", "5", "包邮");
            beans.add(bean);
            beans.add(bean2);
        }
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
        addressRecyclerview.setLayoutManager(linearLayoutManager);
        ShopOrderAdapter adapter = new ShopOrderAdapter(R.layout.shop_order, beans);
        addressRecyclerview.setAdapter(adapter);


    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.lay_back, R.id.c1, R.id.b_titl3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lay_back:
                finish();
                break;
            case R.id.c1:
                Intent intent = new Intent(this, ShopAddress.class);
                startActivity(intent);
                break;
            case R.id.b_titl3:
                if(isBooleans = false){
                    Toast.makeText(getApplicationContext(),"请输入完整地址",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}
